package sys_users

import (
	"context"
	"encoding/json"
	"wave-service/server/app/common/response"

	"wave-service/server/app/internal/svc"
	"wave-service/server/app/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SysUserInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSysUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SysUserInfoLogic {
	return &SysUserInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SysUserInfoLogic) SysUserInfo(req *types.SysUserInfoRequest) (resp *types.SysUserInfoResponse, err error) {
	uid, _ := l.ctx.Value("uid").(json.Number).Int64()
	user, err := l.svcCtx.VisitorsModel.FindOne(l.ctx, uid)
	if err != nil {
		logx.Errorf("获得客服信息失败%v", err.Error())
		return nil, response.Error(500, "系统错误")
	}

	return &types.SysUserInfoResponse{
		Uuid:     user.Uuid,
		Nickname: user.Nickname,
		Avatar:   user.Avatar,
	}, nil
}
